package com.pignest.hotel.ui.reception;

import java.util.List;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Vbox;

import com.pignest.hotel.beans.Booking;
import com.pignest.hotel.service.ReceptionService;
import com.pignest.hotel.spring.Services;
import com.pignest.hotel.util.DateUtil;

public class LivingForm extends Vbox {

	/**
	 * 入住管理
	 */
	private static final long serialVersionUID = -6478820421326451538L;
	private static ReceptionService receptionService;
	private static Listbox bookingList1;
	private static String name;
	private static String mobile;
	public LivingForm(){
		  receptionService=Services.getReceptionService();
		  bookingList1=(Listbox)getFellow("bookingList1");
	}
	 public void onCreate() {
		 bookingList1=(Listbox)getFellow("bookingList1");
	 }
	 public  void init(){
		 bookingList1=(Listbox)getFellow("bookingList1");
	 }
	 public  void queryBooking(){
		 init();
		 bookingList1.getItems().clear();
		   StringBuffer hql=new StringBuffer();
		   hql.append(" from Booking b where 1=1");
		   if(!name.equals(""))
			   hql.append(" and b.name like '%").append(name).append("%'");
		   if(!mobile.equals(""))
			   hql.append(" and b.phone like '%").append(mobile).append("%'");
		   List l =(List)receptionService.find(hql.toString());
		   int Total =l.size();
		   //List<Booking> bookings=receptionService.queryPageHql(hql.toString(), start, pageSize);
		   List<Booking> bookings=receptionService.queryBooking(name, mobile, null);
		  // List<Booking> bookings=receptionService.listAllBookings();
		   //page.setTotalSize(Total);
		   for(final Booking b:bookings){
				
				Listitem listitem = new Listitem();
				listitem.setValue(b.getId());
				listitem.setParent(bookingList1);
				listitem.appendChild(new Listcell(b.getBookingStatus()));
				listitem.appendChild(new Listcell(b.getName()));
				listitem.appendChild(new Listcell(b.getPhone()));
				listitem.appendChild(new Listcell(DateUtil.toFullString(b.getEstimatedTime())));
				//listitem.appendChild(new Listcell(b.getBookingRoomNames()));
				listitem.appendChild(new Listcell(String.valueOf(b.getPreserve()/60)));
				listitem.appendChild(new Listcell(DateUtil.toFullString(b.getEndTime())));
				listitem.appendChild(new Listcell((b.getLeaveTimeLabel())));
				
				listitem.addEventListener(Events.ON_CLICK,  new EventListener(){
					public void onEvent(Event event) throws Exception { 
						//this.selectRoom=r;
						
						//isBookingCkb.setChecked(true);
						System.out.println("********************");
							
					}
				});
			}
	 }
}
